package org.ismarter.badgenumber.badgenumber;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

/**
 * vivo机型的桌面角标设置管理类
 * Created by zlq on 2017 17/8/23 16:35.
 */

public class BadgeNumberManagerVIVO {
    public static final int FLAG_RECEIVER_INCLUDE_BACKGROUND = 0x01000000;

    @SuppressLint("WrongConstant")
    public static void setBadgeNumber(Context context, int number) {
        try {
            Intent intent = new Intent("launcher.action.CHANGE_APPLICATION_NOTIFICATION_NUM");
            intent.putExtra("packageName", context.getPackageName());
            String launchClassName = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()).getComponent().getClassName();
            intent.putExtra("className", launchClassName);
            intent.putExtra("notificationNum", number);
            if ((Build.VERSION.SDK_INT >= 26)) {
                intent.addFlags(FLAG_RECEIVER_INCLUDE_BACKGROUND);
            }
            context.sendBroadcast(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
